package test0.xml;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.Writer;

import javax.sql.rowset.spi.XmlWriter;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;





public class DOM4JWriter {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Document doc=DocumentHelper.createDocument();
		Element root=doc.addElement("root");
		Element linkman=root.addElement("linkman");
		Element name=linkman.addElement("name");
		Element email=linkman.addElement("email");
		name.setText("战场原");
		email.setText("8189");
		OutputFormat format=OutputFormat.createPrettyPrint();
		format.setEncoding("UTF-8");
		
		try {
			XMLWriter writer=new XMLWriter(new FileOutputStream(new File("C:"+File.separator+"Users"+File.separator+"GUO"+File.separator+"Desktop"+File.separator+"address_DOM4J.xml")),format);
			writer.write(doc);
			writer.close();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
